package FeatureEnrichment;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;

import Definitions.GraphClass;
import Definitions.NodeClass;

// Todo (Kadriye) Update Feature enrichment.

public class FeatureSelection 
{
	 public void getSelectedFeaturesIndicesFromFile(GraphClass g,String fileName)
	 {
		int  selectedFeature[][]  = getSelectedIndices(fileName);
		getSelectedFeatures(g, selectedFeature[0]);
	 }
	
	 public void getSelectedFeatures(GraphClass g,int[] selectedFeature)
	 {
		for(NodeClass u: g.getDataSet())
		{
			int k=0;
			for(int i:selectedFeature)
			{
				while(i != k)
				{
					u.getContentList().get(0).getAttributeList().remove(k);
				}
			}
			
		}
		 
	 }
	
	 public int[][] getSelectedIndices(String fileName)
	 {
		 try
		 {
	    	  FileInputStream fstream = new FileInputStream(fileName);
	    	  DataInputStream selectedFeature = new DataInputStream(fstream); 					// getting input file
	    	  BufferedReader br = new BufferedReader(new InputStreamReader(selectedFeature));	// setting the reader class for the input file
	    	  String strLine;
	    	  int selectedFeatureSet[][] = new int[5][600]; 
	    	  
	    	  	// Reading from File Line By Line   than splitting the line <paper_id> <word_attributes>+ <class_label>
	   	  	  int line = 0;
	   	  	  
			  while ((strLine = br.readLine()) != null)
			  {
				  String[] words = strLine.split("	");  				// Splitting words with " "
				  int k=0;
				  
				  for(String s: words)
				  {
					  selectedFeatureSet[line][k] = Integer.parseInt(s);
					  k++;
				  }
				  
			  }
			  
			  selectedFeature.close();
			  return selectedFeatureSet;
		 }
		 catch (Exception e)//Catch exception if any
		 {       
			 System.err.println("Error: " + e.getMessage());
		 }
		 
		return null;    		
	 }
}

